var MaterialPurchaseSelector = {
	getView : function(h, f) {
		var g = null;
		if (f) {
			var g = new Ext.grid.CheckboxSelectionModel({
				singleSelect : true
			});
		} else {
			g = new Ext.grid.CheckboxSelectionModel();
		}
		var b = new Ext.grid.ColumnModel({
			columns : [g, new Ext.grid.RowNumberer(), {
						header : 'id',
						dataIndex : 'id',
						hidden : true
					}, {
						header : '项目名称',
						dataIndex : 'project',
						renderer : function(value, meta, record) {
							if (!Ext.isEmpty(value)) {
								return value.proName;
							}
						}
					}, {
						header : '计划单号',
						dataIndex : 'planNo'
					}, {
						header : '计划日期',
						dataIndex : 'planDate'
					}, {
						header : '质量要求',
						dataIndex : 'quality'
					}]
		});
		var c = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : __ctxPath + "/produce/listMaterialPurchase.do"
			}),
			reader : new Ext.data.JsonReader({
				root : "result",
				totalProperty : "totalCounts",
				fields : [{
						name : 'id',
						type : 'int'
					}, 'project', 'planDate', 'planNo', 'quality', 'createUser', 'createTime']
			}),
			remoteSort : true
		});
		var d = new Ext.grid.GridPanel({
			id : "MaterialPurchaseSelectorGrid",
			width : 500,
			height : 300,
			region : "center",
			title : "物资采购计划列表",
			store : c,
			shim : true,
			trackMouseOver : true,
			disableSelection : false,
			loadMask : true,
			cm : b,
			sm : g,
			viewConfig : {
				forceFit : true,
				enableRowBody : false,
				showPreview : false
			},
			bbar : new Ext.PagingToolbar({
				pageSize : 25,
				store : c,
				displayInfo : true,
				displayMsg : "当前显示从{0}至{1}， 共{2}条记录",
				emptyMsg : "当前没有记录"
			})
		});
		c.load({
			params : {
				start : 0,
				limit : 25
			}
		});
		var a = new Ext.FormPanel({
			width : 500,
			region : "north",
			id : "materialPurchaseSelectorForm",
			height : 40,
			frame : false,
			border : false,
			layout : "hbox",
			layoutConfig : {
				padding : "5",
				align : "middle"
			},
			defaults : {
				xtype : "label",
				margins : {
					top : 0,
					right : 4,
					bottom : 4,
					left : 4
				}
			},
			items : [{
						text : "查询条件:"
					}, {
						style : 'margin-top:5px;',
						xtype : 'label',
						text : '项目编号:'
					}, {
						name : 'Q_project.proName_S_LK',
						xtype : 'textfield'
					}, {
						style : 'margin-top:5px;',
						xtype : 'label',
						text : '计划日期:'
					}, {
						name : 'Q_planDate_D_EQ',
						xtype : 'datefield',
						format:'Y-m-d'
					}, {
						style : 'margin-top:5px;',
						xtype : 'label',
						text : '计划单号:'
					}, {
						name : 'Q_planNo_S_LK',
						xtype : 'textfield'
					}, {
						xtype : "button",
						text : "查询",
						iconCls : "search",
						handler : function() {
							var form = Ext.getCmp("materialPurchaseSelectorForm");
							var grid = Ext.getCmp("MaterialPurchaseSelectorGrid");
							if (form.isValid()) {// 如果合法
								var params = grid.getStore().baseParams;
								Ext.apply(params, form.getValues());
								grid.getStore().load(params);
							}
						}
					}]
		});
		var e = new Ext.Window({
			title : "物资采购计划选择器",
			iconCls : "menu-project",
			width : 700,
			height : 380,
			layout : "border",
			border : false,
			items : [a, d],
			modal : true,
			buttonAlign : "center",
			buttons : [{
						iconCls : "btn-ok",
						text : "确定",
						handler : function() {
							var grid = Ext.getCmp("MaterialPurchaseSelectorGrid");
							var o = grid.getSelectionModel().getSelections();
							var materialPurchaseId = "";
							var proName = "";
							var proId = "";
							var planNo = "";
							var planDate = "";
							var quality = "";
							for (var m = 0; m < o.length; m++) {
								if (m > 0) {
									materialPurchaseId += ",";
									proName += ",";
									proId += ",";
									planNo += ",";
									planDate += ",";
									quality += ",";
								}
								materialPurchaseId += o[m].data.id;
								if(!Ext.isEmpty(o[m].data.project)){
									proName += o[m].data.project.proName;
									proId += o[m].data.project.id;
								}
								planNo += o[m].data.planNo;
								planDate += o[m].data.planDate;
								quality += o[m].data.quality;
							}
							if (h != null) {
								h.call(this, materialPurchaseId, proName, proId,planNo,planDate,quality);
							}
							e.close();
						}
					}, {
						text : "取消",
						iconCls : "btn-cancel",
						handler : function() {
							e.close();
						}
					}]
		});
		return e;
	}
};